﻿using System;
using System.Windows;
using System.Windows.Controls;

using Perseus;

using Hetymine.Executioner.Data;

namespace Hetymine.Executioner.Plugins.General.Network {
    /// <summary>
    /// Interaction logic for ClientConfigurator.xaml
    /// </summary>
    public partial class ClientConfigurator : UserControl, IConfigurator<ClientConfiguratorItem> {
        private ClientConfiguratorItem _Config;
        private bool _IsApply = false;

        public ClientConfigurator() {
            InitializeComponent();

            this.cName.TextChanged += new TextChangedEventHandler(Name_TextChanged);
            this.cIdentifier.TextChanged += new TextChangedEventHandler(Identifier_TextChanged);
            this.cBroadcast.Click += new RoutedEventHandler(Broadcast_Click);
        }        
        private void Name_TextChanged(object sender, TextChangedEventArgs e) {
            if (!this._IsApply) { return; }

            this._Config.Name = this.cName.Text;
        }
        private void Identifier_TextChanged(object sender, TextChangedEventArgs e) {
            if (!this._IsApply) { return; }

            this._Config.Identifier = this.cIdentifier.Text;
        }
        private void Broadcast_Click(object sender, RoutedEventArgs e) {
            if (!this._IsApply) { return; }

            this._Config.Broadcast = this.cBroadcast.IsChecked;
        }
        #region IConfigurator<ClientConfigurator> Members
        public UserControl ConfigPanel {
            get { throw new NotImplementedException(); }
        }

        public void InitializeConfig(ClientConfiguratorItem config) {
            this._Config = config;
            

            this._IsApply = false;

            this.cName.Text = config.Name;
            this.cIdentifier.Text = config.Identifier;
            this.cBroadcast.IsChecked = config.Broadcast;

            this._IsApply = true;
        }
        #endregion
    }
}
